package com.yhgm.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class DateConverter {
    public static String convertToElasticsearchFormat(String inputDateStr) {
        try {
            SimpleDateFormat inputFormat = new SimpleDateFormat("MMM d, yyyy, h:mm:ss a", Locale.ENGLISH);
            SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZ", Locale.ENGLISH);
            Date date = inputFormat.parse(inputDateStr);
            return outputFormat.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void main(String[] args) {
        String inputDateStr = "Feb 2, 2012, 4:18:06 AM";
        String elasticsearchFormattedDate = convertToElasticsearchFormat(inputDateStr);
        System.out.println(elasticsearchFormattedDate);
    }
}
